package com.woniu.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.woniu.entity.CreExamineNew;
import com.woniu.entity.CreRefund;
import com.woniu.service.CreditExamineNewService;
import com.woniu.service.CreditExamineService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.java2d.pipe.AAShapePipe;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;


@RestController
@RequestMapping("/credit/examineNew")
public class CreditExamineNewController extends BaseController {
    @Autowired
    private CreditExamineNewService creditExamineNewService;

    /**
     * 查询列表
     */
    @PostMapping("/list")
    @ApiOperation("查询审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examineId", value = "订单编号", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderId", value = "用户id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "creditRecord", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "overdue", value = "产品id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "exceedsCapacity", value = "产品名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "singleDebt", value = "提交时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "singleGuaranteeDebt", value = "申请金额", dataType = "double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "execution", value = "贷款期限(查字典)", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "mateExecution", value = "还款方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorExecution", value = "还款状态", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorMateExecution", value = "还款金额", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "dishonesty", value = "审核人", dataType = "String", dataTypeClass = String.class),
    })
    public TableDataInfo list(@RequestBody CreExamineNew creExamineNew)
    {
        startPage();
        List<CreExamineNew> list = creditExamineNewService.selectCreExamineNewList(creExamineNew);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */
    @PostMapping("/export")
    @ApiOperation("导出审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examineId", value = "订单编号", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderId", value = "用户id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "creditRecord", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "overdue", value = "产品id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "exceedsCapacity", value = "产品名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "singleDebt", value = "提交时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "singleGuaranteeDebt", value = "申请金额", dataType = "double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "execution", value = "贷款期限(查字典)", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "mateExecution", value = "还款方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorExecution", value = "还款状态", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorMateExecution", value = "还款金额", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "dishonesty", value = "审核人", dataType = "String", dataTypeClass = String.class),
    })
    public void export(HttpServletResponse response, CreExamineNew creExamineNew)
    {
        List<CreExamineNew> list = creditExamineNewService.selectCreExamineNewList(creExamineNew);
        ExcelUtil<CreExamineNew> util = new ExcelUtil<CreExamineNew>(CreExamineNew.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{examineId}")
    @ApiOperation("查询审核列表")
    @ApiImplicitParam(name = "examineId", value = "审核编号", dataType = "int", dataTypeClass = Integer.class)
    public AjaxResult getInfo(@PathVariable("examineId") Integer examineId)
    {
        return AjaxResult.success(creditExamineNewService.selectCreExamineNewByExamineId(examineId));
    }

    /**
     * 获取详细信息
     */
    @PostMapping("/byOrderId")
    @ApiOperation("获取审核列表")
    @ApiImplicitParam(name = "orderId", value = "订单编号", dataType = "int", dataTypeClass = Integer.class)
    public AjaxResult getInfoByOrderId(@RequestBody Integer orderId)
    {
        return AjaxResult.success(creditExamineNewService.selectCreExamineNewByOrderId(orderId));
    }

    /**
     * 新增
     */
    @PostMapping
    @ApiOperation("新增审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examineId", value = "订单编号", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderId", value = "用户id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "creditRecord", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "overdue", value = "产品id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "exceedsCapacity", value = "产品名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "singleDebt", value = "提交时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "singleGuaranteeDebt", value = "申请金额", dataType = "double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "execution", value = "贷款期限(查字典)", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "mateExecution", value = "还款方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorExecution", value = "还款状态", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorMateExecution", value = "还款金额", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "dishonesty", value = "审核人", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult add(@RequestBody CreExamineNew creExamineNew)
    {
        int result = creditExamineNewService.insertCreExamineNew(creExamineNew);
        if(result==-1){
            return AjaxResult.error("初审已通过，不能重复初审");
        }
        return toAjax(result);
    }

    /**
     * 修改
     */
    @PutMapping
    @ApiOperation("修改审核列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examineId", value = "订单编号", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderId", value = "用户id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "creditRecord", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "overdue", value = "产品id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "exceedsCapacity", value = "产品名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "singleDebt", value = "提交时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "singleGuaranteeDebt", value = "申请金额", dataType = "double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "execution", value = "贷款期限(查字典)", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "mateExecution", value = "还款方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorExecution", value = "还款状态", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorMateExecution", value = "还款金额", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "dishonesty", value = "审核人", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult edit(@RequestBody CreExamineNew creExamineNew)
    {
        return toAjax(creditExamineNewService.updateCreExamineNew(creExamineNew));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{examineIds}")
    public AjaxResult remove(@PathVariable Integer[] examineIds)
    {
        return toAjax(creditExamineNewService.deleteCreExamineNewByExamineIds(examineIds));
    }


    /**机器审核*/
    @PostMapping("/machineAudit")
    @ApiOperation("机器审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "examineId", value = "订单编号", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderId", value = "用户id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "creditRecord", value = "用户名", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "overdue", value = "产品id(外键)", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "exceedsCapacity", value = "产品名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "singleDebt", value = "提交时间", dataType = "Date", dataTypeClass = Date.class),
            @ApiImplicitParam(name = "singleGuaranteeDebt", value = "申请金额", dataType = "double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "execution", value = "贷款期限(查字典)", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "mateExecution", value = "还款方式", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorExecution", value = "还款状态", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "guarantorMateExecution", value = "还款金额", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "dishonesty", value = "审核人", dataType = "String", dataTypeClass = String.class),
    })
    public AjaxResult machineAudit(@RequestBody CreExamineNew creExamineNew){
        System.out.println("进入");
        return AjaxResult.success(creditExamineNewService.machineAudit(creExamineNew));
    }


    /**获得审核人用户名*/
    @GetMapping("/getUserName")
    public AjaxResult getUserName(){
       String userName=creditExamineNewService.getUserName();
        System.out.println(AjaxResult.success(userName));
         return AjaxResult.success(userName);
    }
}
